package com.hyts.infodb.zuul.config;

import com.hyts.infodb.error.advice.SystemExceptionHandler;
import com.hyts.infodb.zuul.filter.AuthAccessFilter;
import com.hyts.infodb.zuul.locator.CustomRouteLocator;
import com.hyts.infodb.zuul.service.ZuulService;
import lombok.NoArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.web.ServerProperties;
import org.springframework.boot.web.servlet.error.ErrorController;
import org.springframework.cloud.netflix.zuul.EnableZuulProxy;
import org.springframework.cloud.netflix.zuul.filters.RouteLocator;
import org.springframework.cloud.netflix.zuul.filters.ZuulProperties;
import org.springframework.cloud.netflix.zuul.web.ZuulHandlerMapping;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

/**
 * @project-name:infodb
 * @package-name:com.hyts.infodb.zuul.config
 * @author:Libo/Alex
 * @create-date:2019-05-22 21:38
 * @copyright:libo-hyts-github
 * @email:libo2dev@aliyun.com
 * @description:此类主要用于:
 */
@NoArgsConstructor
@EnableZuulProxy
@Configuration
public class ZuulConfiguration {


    @Autowired
    ZuulService zuulService;


    @Autowired
    ZuulProperties zuulProperties;


    @Autowired
    ServerProperties serverProperties;



    @Bean("customRouteLocator")
    public RouteLocator customRouteLocator(){
        CustomRouteLocator customRouteLocator = new CustomRouteLocator("/",zuulProperties);
        customRouteLocator.setZuulService(zuulService);
        return customRouteLocator;
    }


    /*@Bean
    public ZuulHandlerMapping zuulHandlerMapping(RouteLocator routes,ErrorController errorController) {
        ZuulHandlerMapping mapping = new ZuulHandlerMapping(routes, zuulController());
        mapping.setErrorController(errorController);
        mapping.setCorsConfigurations(getCorsConfigurations());
        return mapping;
    }*/

//    @Bean
//    public AuthAccessFilter authAccessFilter(){
//        return new AuthAccessFilter();
//    }

    @Bean
    public SystemExceptionHandler systemExceptionHandler(){
        return new SystemExceptionHandler();
    }

}
